 
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>下拉菜单组件文档 - Layui</title>
<meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <script>
  ;!function(){self!==parent&&(location.href="//www.baidu.com/")}();
  </script>
  <link rel="stylesheet" href="../../layui/dist/css/layui.css" media="all">
  <link rel="stylesheet" href="../../static/css/global.css" media="all">
</head>
<body><div class="layui-header header header-doc" autumn="">
  <div class="layui-container">
    <a class="logo" href="../../index.html">
      <img src="../../static/images/layui/logo.png" alt="layui">
    </a>
    <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
    <div class="layui-hide-xs site-notice"></div>
    
    <ul class="layui-nav" id="LAY_NAV_TOP">
      <li class="layui-nav-item layui-this">
        <a href="../index.html">文档</a> 
      </li>
      <li class="layui-nav-item ">
        <a href="../../demo/index.html">示例</a>
      </li>
      
      <li class="layui-nav-item">
        <a href="javascript:;">
          <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
          周边
        </a>
        <dl class="layui-nav-child layui-nav-child-c">  
          <dd class="layui-hide-sm layui-show-xs" lay-unselect="">
            <a href="javascript:window.open('https://gitee.com/sentsin/layui/issues');" target="_blank" rel="nofollow">问题反馈</a>
            <hr>
          </dd>
          
          <dd lay-unselect=""><a href="../../alone.html" target="_blank" lay-unselect="">独立组件</a></dd>
          <dd lay-unselect=""><a href="../../extend/index.html" target="_blank">扩展组件</a></dd>
        </dl>
      </li>
      
      
    </ul>
  </div>
</div>
 
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<ul class="site-dir">
  <li><a href="#use"><cite>快速使用</cite></a></li>
  <li><a href="#options"><cite>基础参数</cite></a></li>
  <li><a href="#data"><cite>菜单项参数</cite></a></li>
  <li><a href="#onclick"><cite>菜单被点击的回调</cite></a></li>
  <li><a href="#templet"><cite>自定义菜单项模板</cite></a></li>
  <li><a href="#contextmenu"><cite>右键菜单</cite></a></li>
  <li><a href="../../demo/dropdown.html" target="_blank"><cite>查看组件示例</cite></a></li>
</ul>
<div class="layui-container layui-row">
  
<div class="layui-col-md3">
  <div class="layui-panel site-menu">
    <ul class="layui-menu layui-menu-lg">
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          基础说明
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../index.html">
                <span>开始使用 </span> 
                <span class="layui-font-12 layui-font-gray">Getting Started</span>
              </a>
              
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/infrastructure.html">
                <span>底层方法 </span>
                <span class="layui-font-12 layui-font-gray">基础支撑</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/element.html">
                <span>页面元素 </span>
                <span class="layui-font-12 layui-font-gray">规范 公共类 属性</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/modules.html">
                <span>模块规范 </span>
                <span class="layui-font-12 layui-font-gray">使用 扩展</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/faq.html">
                <span>常见问题 </span>
                <span class="layui-font-12 layui-font-gray">FAQ</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/changelog.html">
                <span>更新日志 </span>
                <span class="layui-font-12 layui-font-gray">changelog</span>
                
                  <span class="layui-badge-dot"></span>
                
              </a>
            </div>
          </li>
        </ul>
      </li>
      
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          页面元素
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/layout.html">
                <span>布局 </span>
                <span class="layui-font-12 layui-font-gray">栅格 后台管理布局</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/color.html">
                <span>颜色 </span>
                <span class="layui-font-12 layui-font-gray">主色调 颜色搭配</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/icon.html">
                <span>图标 </span>
                <span class="layui-font-12 layui-font-gray">iconfont 字体图标</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/anim.html">
                <span>动画 </span>
                <span class="layui-font-12 layui-font-gray">内置 CSS3 动画</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/button.html">
                <span>按钮 </span>
                <span class="layui-font-12 layui-font-gray">button</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/form.html">
                <span>表单 </span>
                <span class="layui-font-12 layui-font-gray">form 元素集合</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/nav.html">
                <span>导航 </span>
                <span class="layui-font-12 layui-font-gray">nav 面包屑</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/menu.html">
                <span>菜单 </span>
                <span class="layui-font-12 layui-font-gray">menu 基础菜单</span>
                
                  <span class="layui-badge-dot"></span>
                
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/tab.html">
                <span>选项卡 </span>
                <span class="layui-font-12 layui-font-gray">Tabs 切换</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/progress.html">
                <span>进度条 </span>
                <span class="layui-font-12 layui-font-gray">progress</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/panel.html">
                <span>面板 </span>
                <span class="layui-font-12 layui-font-gray">panel 卡片 折叠</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/table.html">
                <span>表格 </span>
                <span class="layui-font-12 layui-font-gray">静态 table</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/badge.html">
                <span>徽章 </span>
                <span class="layui-font-12 layui-font-gray">小圆点  小边框</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/timeline.html">
                <span>时间线 </span>
                <span class="layui-font-12 layui-font-gray">timeline</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../element/auxiliar.html">
                <span>辅助 </span>
                <span class="layui-font-12 layui-font-gray">引用 字段集 横线等</span>
              </a>
            </div>
          </li>
        </ul>
      </li>
      
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          内置模块
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="layer.html">
                <span>弹出层 </span>
                <span class="layui-font-12 layui-font-gray">layer</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="laydate.html">
                <span>日期与时间选择 </span>
                <span class="layui-font-12 layui-font-gray">laydate</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="laypage.html">
                <span>分页 </span>
                <span class="layui-font-12 layui-font-gray">laypage</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="laytpl.html">
                <span>模板引擎 </span>
                <span class="layui-font-12 layui-font-gray">laytpl</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="table.html">
                <span>数据表格 </span>
                <span class="layui-font-12 layui-font-gray">table</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="form.html">
                <span>表单 </span>
                <span class="layui-font-12 layui-font-gray">form</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="upload.html">
                <span>文件上传 </span>
                <span class="layui-font-12 layui-font-gray">upload</span>
              </a>
            </div>
          </li>
          <li class="layui-menu-item-checked2">
            <div class="layui-menu-body-title">
              <a href="">
                <span>下拉菜单 </span>
                <span class="layui-font-12 layui-font-gray">dropdown</span>
                
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="transfer.html">
                <span>穿梭框 </span>
                <span class="layui-font-12 layui-font-gray">transfer</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="tree.html">
                <span>树形组件 </span>
                <span class="layui-font-12 layui-font-gray">tree</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="colorpicker.html">
                <span>颜色选择器 </span>
                <span class="layui-font-12 layui-font-gray">colorpicker</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="element.html">
                <span>常用元素操作 </span>
                <span class="layui-font-12 layui-font-gray">element</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="slider.html">
                <span>滑块 </span>
                <span class="layui-font-12 layui-font-gray">slider</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="rate.html">
                <span>评分 </span>
                <span class="layui-font-12 layui-font-gray">rate</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="carousel.html">
                <span>轮播 </span>
                <span class="layui-font-12 layui-font-gray">carousel</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="flow.html">
                <span>流加载 </span>
                <span class="layui-font-12 layui-font-gray">flow</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="util.html">
                <span>工具组件 </span>
                <span class="layui-font-12 layui-font-gray">util</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="code.html">
                <span>代码高亮显示 </span>
                <span class="layui-font-12 layui-font-gray">code</span>
              </a>
            </div>
          </li>
<li class="">
            <div class="layui-menu-body-title">
              <a href="layedit.html">
                <span>富文本编辑器 </span>
                <span class="layui-font-12 layui-font-gray">layedit</span>
              </a>
            </div>
          </li>
        </ul>
      </li>
    </ul>
  </div>
  <div class="layui-hide-v"> - </div>
</div>

  
  <div class="layui-col-md9 site-content">
    <h1 class="site-h1">下拉菜单组件文档 - layui.dropdown</h1>
    <blockquote class="layui-elem-quote layui-text">
      dropdown 是基于 layui「基础菜单」结构衍生的多功能通用下拉菜单组件，它将原本静态呈现的菜单，通过各种事件的形式触发，从而以独立面板的形式弹出。不仅可用作常见的「下拉菜单」，更可用于「右键菜单」来实现更多的交互可能。
    </blockquote>
    <blockquote class="layui-elem-quote layui-text">
      模块加载名称：<em>dropdown</em>
    </blockquote>
    
    
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="use">快速使用</a></legend>
    </fieldset>
    <div class="site-text">
      <div class="layui-tab layui-tab-brief layui-code-demo">
        <ul class="layui-tab-title">
          <li class="layui-this">代码</li>
          <li>演示效果</li>
        </ul>
        <div class="layui-tab-content layui-border layui-bg-gray">
          <div class="layui-tab-item layui-show">
            <pre class="layui-code" id="docDemoCode1" lay-height="300px">
&lt;button class=&quot;layui-btn&quot; id=&quot;demo1&quot;&gt;
  下拉菜单
  &lt;i class=&quot;layui-icon layui-icon-down layui-font-12&quot;&gt;&lt;/i&gt;
&lt;/button&gt;
 
&lt;script&gt;
layui.use('dropdown', function(){
  var dropdown = layui.dropdown
  dropdown.render({
    elem: '#demo1' //可绑定在任意元素中，此处以上述按钮为例
    ,data: [{
      title: 'menu item 1'
      ,id: 100
      ,href: '#'
    },{
      title: 'menu item 2'
      ,id: 101
      ,href: 'https://www.layui.com/' //开启超链接
      ,target: '_blank' //新窗口方式打开
    },{type: '-'},{
      title: 'menu item 3'
      ,id: 102
      ,type: 'group'  //菜单类型，支持：normal/group/parent/-
      ,child: [{
        title: 'menu item 3-1'
        ,id: 103
      },{
        title: 'menu item 3-2'
        ,id: 104
        ,child: [{
          title: 'menu item 3-2-1'
          ,id: 105
        },{
          title: 'menu item 3-2-2'
          ,id: 106
        }]
      },{
        title: 'menu item 3-3'
        ,id: 107
      }]
    },{type: '-'},{
      title: 'menu item 4'
      ,id: 108
    },{
      title: 'menu item 5'
      ,id: 109
      ,child: [{
        title: 'menu item 5-1'
        ,id: 11111
        ,child: [{
          title: 'menu item 5-1-1'
          ,id: 2111
        },{
          title: 'menu item 5-1-2'
          ,id: 3111
        }]
      },{
        title: 'menu item 5-2'
        ,id: 52
      }]
    },{type:'-'},{
      title: 'menu item 6'
      ,id: 6
      ,type: 'group'
      ,isSpreadItem: false
      ,child: [{
        title: 'menu item 6-1'
        ,id: 61
      },{
        title: 'menu item 6-2'
        ,id: 62
      }]
    }]
    ,id: 'demo1'
    //菜单被点击的事件
    ,click: function(obj){
      console.log(obj);
      layer.msg('回调返回的参数已显示再控制台');
    }
  });
});
&lt;/script&gt;
            </pre>
          </div>
          <div class="layui-tab-item" id="docDemoView1" style="height:311px;"></div>
        </div>
      </div>
      <blockquote class="layui-elem-quote layui-text">菜单列表核心的数据来自于 data 参数，详细可参加右边目录「菜单列参数」</blockquote>
    </div> 
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="options">基础参数</a></legend>
    </fieldset>
    <div class="site-text">
      <p>即核心方法 <code>dropdown.render(options)</code> 中的 options 对应的参数：</p>
      
      <table class="layui-table">
        <colgroup>
          <col width="100">
          <col>
          <col width="100">
          <col width="100">
        </colgroup>
        <thead>
          <tr>
            <th>参数</th>
            <th>说明</th>
            <th>类型</th>
            <th>默认值</th>
          </tr> 
        </thead>
        <tbody>
          <tr>
            <td>elem</td>
            <td>绑定触发组件的元素。必填项</td>
            <td>String/DOM</td>
            <td>-</td>
          </tr>
          <tr>
            <td>data</td>
            <td>菜单列数据项，其参数详见下文。必填项</td>
            <td>Array</td>
            <td>[]</td>
          </tr>
          <tr>
            <td>trigger</td>
            <td>触发组件的事件类型。支持所有事件，如：click/hover/mousedown/contextmenu 等</td>
            <td>String</td>
            <td>click</td>
          </tr>
          <tr>
            <td>show</td>
            <td>是否初始即显示组件面板</td>
            <td>Boolean</td>
            <td>false</td>
          </tr>
          <tr>
            <td>align</td>
            <td>
              下拉面板相对绑定元素的水平对齐方式（支持: left/center/right）
              <span class="layui-font-red">v2.6.8 新增</span>
            </td>
            <td>String</td>
            <td>left</td>
          </tr>
          <tr>
            <td>isAllowSpread</td>
            <td>是否允许菜单组展开收缩</td>
            <td>Boolean</td>
            <td>true</td>
          </tr>
          <tr>
            <td>isSpreadItem</td>
            <td>是否初始展开子菜单</td>
            <td>Boolean</td>
            <td>true</td>
          </tr>
          <tr>
            <td>delay</td>
            <td>延迟关闭的毫秒数。当 trigger 为 hover 时才生效</td>
            <td>Number</td>
            <td>300</td>
          </tr>
          <tr>
            <td>className</td>
            <td>自定义组件的样式类名</td>
            <td>String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>style</td>
            <td>设置组件的 style 属性，从而定义新的样式</td>
            <td>String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>templet</td>
            <td>全局定义菜单的列表模板，添加任意 html 字符，模版将被 laytpl 组件所转义，因此可通过 {{ d.title }} 的方式得到当前菜单配置的数据。<a href="#templet">#详见</a></td>
            <td>String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>content</td>
            <td>自定义组件内容，从而替代默认的菜单结构</td>
            <td>String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>ready</td>
            <td>
              组件成功弹出后的回调，并返回两个参数，如：
              <pre class="layui-code" lay-lang="JS">
ready: function(elemPanel, elem){
  console.log(elemPanel); 得到组件面板的 DOM 对象
  console.log(elem); 得到基础参数 elem 所绑定的元素 DOM 对象
}              
              </pre>
            </td>
            <td>Function</td>
            <td>-</td>
          </tr>
          <tr>
            <td>click</td>
            <td>
              菜单项被点击时的回调，并返回两个参数，如：
              <pre class="layui-code" lay-lang="JS">
click: function(data, othis){
  console.log(data); 得到当前所点击的菜单项对应的数据
  console.log(othis); 得到当前所点击的菜单项 DOM 对象
  console.log(this.elem); //得到当前组件绑定的原始 DOM 对象，批量绑定中常用。
}              
              </pre>
              <a href="#onclick">#详细使用参见下文</a>
            </td>
            <td>Function</td>
            <td>-</td>
          </tr>
        </tbody>
      </table>
    </div>
    
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="data">菜单项参数</a></legend>
    </fieldset>
    
    <div class="site-text">
      <p>即上述基础参数 <code>data</code> 对应的参数，格式为：<code>data: [{title: 'menu item 1', id: 1}, {}, {}]</code></p>
      <table class="layui-table">
        <colgroup>
          <col width="100">
          <col>
          <col width="100">
          <col width="200">
        </colgroup>
        <thead>
          <tr>
            <th>参数</th>
            <th>说明</th>
            <th>类型</th>
            <th>默认值</th>
          </tr> 
        </thead>
        <tbody>
          <tr>
            <td>title</td>
            <td>菜单标题</td>
            <td>String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>id</td>
            <td>菜单 ID。用户菜单项唯一索引</td>
            <td>Number/String</td>
            <td>-</td>
          </tr>
          <tr>
            <td>href</td>
            <td>菜单项的超链接地址。若填写，点击菜单将直接发生跳转。</td>
            <td>String</td>
            <td>false</td>
          </tr>
          <tr>
            <td>target</td>
            <td>
              菜单项超链接的打开方式，需 href 填写才生效。
              <br>一般可设为 _blank 或 _self 等
            </td>
            <td>String</td>
            <td>_self</td>
          </tr>
          <tr>
            <td>type</td>
            <td>菜单项的类型，当前支持的值如下：
              <blockquote class="layui-elem-quote layui-text" style="margin-top: 10px;">
                <em>normal</em>（默认）
                <br><em>group</em>（垂直菜单组）
                <br><em>parent</em>（横向父子菜单）
                <br><em>-</em>（分割线）
              </blockquote>
            </td>
            <td>String</td>
            <td>normal 或 不填</td>
          </tr>
          <tr>
            <td>child</td>
            <td>子级菜单数据项。参数同父级，可无限嵌套。</td>
            <td>Array</td>
            <td>[]</td>
          </tr>
          <tr>
            <td>templet</td>
            <td>自定义当前菜单项模板，优先级高于全局设定的 templet。详见下文。</td>
            <td>String</td>
            <td>-</td>
          </tr>
        </tbody>
      </table>
    </div>
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="onclick">菜单项被点击的回调</a></legend>
    </fieldset>
    
    <div class="site-text">
      <div class="layui-tab layui-tab-brief layui-code-demo">
        <ul class="layui-tab-title">
          <li class="layui-this">代码</li>
          <li>演示效果</li>
        </ul>
        <div class="layui-tab-content layui-border layui-bg-gray">
          <div class="layui-tab-item layui-show">
            <pre class="layui-code" id="docDemoCode2" lay-height="300px" lay-encode="true">
<table class="layui-table">   
  <tbody>
    <tr>
      <td>列表 1</td>
      <td><button class="layui-btn layui-btn-sm demolist" data-id="111">更多操作</button></td>
    </tr>
    <tr>
      <td>列表 2</td>
      <td><button class="layui-btn layui-btn-sm demolist" data-id="222">更多操作</button></td>
    </tr>
    <tr>
      <td>列表 3</td>
      <td><button class="layui-btn layui-btn-sm demolist" data-id="333">更多操作</button></td>
    </tr>
  </tbody>
</table>
&lt;script&gt;
layui.use('dropdown', function(){
  var dropdown = layui.dropdown
  ,$ = layui.jquery;
  
  dropdown.render({
    elem: '.demolist'
    ,data: [{
      title: 'item 1'
      ,id: 'aaa'
    }, {
      title: 'item 2'
      ,id: 'bbb'
    }]
    ,click: function(data, othis){
      var elem = $(this.elem)
      ,listId = elem.data('id'); //表格列表的预埋数据
      layer.msg('得到表格列表的 id：'+ listId +'，下拉菜单 id：'+ data.id);
    }
  });
});
&lt;/script&gt;
            </pre>
          </div>
          <div class="layui-tab-item" id="docDemoView2"></div>
        </div>
      </div>
    </div>
    
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="templet">自定义菜单项模板</a></legend>
    </fieldset>
    <div class="site-text">
      <p>通过 templet 参数即可自定义菜单项模板，其字符将被 laytpl 组件所转义，因此可通过 undefined 的方式得到当前菜单配置的数据。</p>
      <pre class="layui-code" lay-lang="JS">
var dropdown = layui.dropdown;
 
//执行菜单
dropdown.render({
  elem: '#id'
  ,data: [{
    title: '刷新'
    //当设定了模板时，菜单项将优先显示模板结构；否则将默认显示标题
    ,templet: '&lt;i class=&quot;layui-icon layui-icon-refresh&quot;&gt;&lt;/i&gt; {{d.title}}'
    ,id: 100
  },{
    title: 'menu item 2'
    //该模板由「图片+标题+徽章」组成
    ,templet: '&lt;img src=&quot;1.jpg&quot; style=&quot;width: 16px;&quot;&gt; {{d.title}} &lt;span class=&quot;layui-badge-dot&quot;&gt;&lt;/span&gt;'
    ,id: 101
    ,href: 'https://www.layui.com/'
    ,target: '_blank'
  },{
    title: 'menu item 3' //未开启模板时，默认直接显示标题
    ,id: 103
  }]
})  
      </pre>
    </div>
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="contextmenu">右键菜单</a></legend>
    </fieldset>
    <div class="site-text">
      <p>当参数设定为 <code>trigger: 'contextmenu'</code>时，即会在所绑定的元素中屏蔽默认的右键菜单，从而呈现 dropdown 组件配置的菜单。</p>
      <pre class="layui-code" lay-height="300px" lay-lang="JS">
var dropdown = layui.dropdown;
 
//执行菜单
dropdown.render({
  elem: '#demo' //在 id="demo" 的元素中触发事件。也可以直接设置为 document，从而重置整个右键菜单
  ,trigger: 'contextmenu' //右键事件
  ,data: [{
    title: 'menu item 1'
    ,id: 1
  },{
    title: 'menu item 2'
    ,id: 'reload'
  },{type:'-'},{
    title: 'menu item 3'
    ,id: 3
    ,child: [{
      title: 'menu item 3-1'
      ,id: 31
    },{
      title: 'menu item 3-2'
      ,id: 32
    },{
      title: 'menu item 3-3'
      ,id: 33
    }]
  },{type:'-'},{
    title: 'menu item 4'
    ,id: 111
  },{
    title: 'menu item 5'
    ,id: 555
  },{
    title: 'menu item 6'
    ,id: 666
  }]
});
      </pre>
    </div>
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="docend">结语</a></legend>
    </fieldset>
    <div class="site-text">
      <p>该组件使用非常灵活，且弹出的面板进行了坐标的科学判断（基于内部的 lay.js 模块），能始终吸附显示在最佳的位置。</p>
    </div>
    
    <div class="layui-elem-quote">
  <p>layui - 在每一个细节中，用心与你沟通</p>
</div>
    
  </div>
</div>
  
<script>
window.global = {
  pageType: 'doc'
  ,preview: function(){
    var preview = document.getElementById('LAY_preview');
    return preview ? preview.innerHTML : '';
  }()
};
</script>
<script async="" src="../../pagead/js/adsbygoogle.js"></script>
<div class="site-tree-mobile layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
<div class="site-mobile-shade"></div>
 
<script src="../../layui/dist/layui.js" ></script>
<script>
layui.config({
  base: '../../static/lay/modules/layui/'
  ,version: '1632428048260'
}).use('global');
</script>
 <script>
global.docDemoCode1 = document.getElementById('docDemoCode1').innerHTML;
global.docDemoCode2 = document.getElementById('docDemoCode2').innerHTML;
layui.use(['dropdown', 'util', 'layer'], function(){
  var dropdown = layui.dropdown
  ,util = layui.util
  ,layer = layui.layer
  ,$ = layui.jquery;
  
  //临时写法
  $('#docDemoView1').html(util.unescape(global.docDemoCode1));
  $('#docDemoView2').html(util.unescape(global.docDemoCode2));
});
</script>
</body>
</html>